package com.example.feitiansys.controller;

import com.example.feitiansys.pojo.Badness;
import com.example.feitiansys.service.badness.BadnessService;
import com.sun.jna.platform.win32.DdemlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * author:武欣阳
 */
@Controller
public class BadController {
    @Autowired
    BadnessService badnessService;
    @RequestMapping("/system/badness/update")
    public String update(){
        return "/system/badness/update";
    }
    @RequestMapping("/system/badness")
    public String leaveshow(){
        return "system/badness/badness";
    }
    @RequestMapping("/system/badness/add")
    public String leaveaddshow(){
        return "system/badness/add";
    }
    @RequestMapping("/system/badness/getallbadness")
    @ResponseBody
    public Object getAllBadness(Badness badness) {
        if (badness == null) {
            badness = new Badness();
        }
        return badnessService.getAllBadness(badness);
    }

    @RequestMapping("/system/badness/getbadnessbyid")
    @ResponseBody
    public Badness getBadnessById(Integer id){
        return badnessService.selectBadnessById(id);
    }
    @RequestMapping("/system/badness/removebadness")
    @ResponseBody
    public Object removeBadness(Integer id){
        return badnessService.removeBadness(id);
    }
    @RequestMapping("/system/badness/removeallbadness")
    @ResponseBody
    public Object removeAllBadness(String array){
        String[] split = array.split(",");
        return badnessService.removeLeaveByIds(split);
    }
    @RequestMapping("/system/badness/addbadness")
    @ResponseBody
    public Integer addBadness(Badness badness){
        Date date = new Date();
        badness.setCreatetime(date);
        int insert = badnessService.addBadness(badness);
        return insert;
    }
    @RequestMapping("/system/badness/updatebadness")
    @ResponseBody
    public Object updateBadness(Badness badness){
        return badnessService.changeBadness(badness);
    }

}
